package com.datawin.taotaocheche.ui.actviity.login.presenter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import com.datawin.taotaocheche.base.BaseBiz;
import com.datawin.taotaocheche.bean.CityInfo;
import com.datawin.taotaocheche.ui.actviity.login.biz.CityBiz;
import com.datawin.taotaocheche.ui.actviity.login.contract.CityContract;

/**
 * Created by Administrator on 2017/10/21.
 */

public class CityPresenter implements CityContract.Presenter {

    CityContract.View view;
    CityBiz cityBiz;


    @Inject
    public CityPresenter(CityContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        cityBiz = (CityBiz) biz;

    }

    @Override
    public void getData() {
        view.loading(true);
        cityBiz.getiCity(new BaseBiz.Callback<List<CityInfo>>() {
            @Override
            public void onSuccess(List<CityInfo> info) {
                List<String> hotCity = new ArrayList<>();
                for (CityInfo cityInfo : info) {
                    if(cityInfo.getRank()==1){
                        hotCity.add(cityInfo.getName());
                    }

                }
                view.updateImages(info,hotCity);
                view.loading(false);


            }

            @Override
            public void onFailure(List<CityInfo> info) {
                view.loading(false);
            }
        });
    }
}
